package com.huoyun.car.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.huoyun.base.dao.BaseDaoImpl;
import com.huoyun.car.bean.Car;
import com.huoyun.car.dao.evt.QueryCarEvt;
import com.huoyun.car.model.CarDriverOwnerModel;
import com.huoyun.car.model.CarModel;
import com.huoyun.car.model.CarUserCompanyModel;
import com.huoyun.user.bean.User;

public class CarDaoImpl extends BaseDaoImpl<Car> implements CarDao{

	public void saveCar(Car car) 
	{
		sqlSessionTemplate.insert("com.huoyun.car.dao.CarDaoMapper.saveCar", car);
	}

	public void updateAll(Car car)
	{
		sqlSessionTemplate.update("com.huoyun.car.dao.CarDaoMapper.updateAll",car);
	}
	
	public Car getCarById(long carId)
	{
		return sqlSessionTemplate.selectOne("com.huoyun.car.dao.CarDaoMapper.getCarById",carId);
	}
	
	public void delete(long carId)
	{
		sqlSessionTemplate.delete("com.huoyun.car.dao.CarDaoMapper.delete",carId);
	}

	@Override
	public List<Car> getCarListByUserId(long userId) {
		return sqlSessionTemplate.selectList("com.huoyun.car.dao.CarDaoMapper.getCarListByUserId",userId);
	}
	
	public List<Car> getUnPublishedCarListByUserId(long userId) {
		return this.sqlSessionTemplate.selectList("com.huoyun.car.dao.CarDaoMapper.getUnPublishedCarListByUserId", userId);
	}
	
	public User getUserByCarId(long carId) {
		return this.sqlSessionTemplate.selectOne("com.huoyun.car.dao.CarDaoMpper.getUserByCarId", carId);
	}

//	@Override
//	public List<Car> getCarListByLoadMaxForUser(long userId, String loadMax) {
//		// TODO Auto-generated method stub
//		Map<String,String> map=new HashMap<String,String>();
//		map.put("userId", userId+"");
//		map.put("load", loadMax+"");
//		return this.sqlSessionTemplate.selectList("com.huoyun.car.dao.CarDaoMapper.getCarListByWeightForUser", map);
//	}

	@Override
	public List<Car> getCarListByUsername(String username) {
		// TODO Auto-generated method stub
		return this.sqlSessionTemplate.selectList("com.huoyun.car.dao.CarDaoMapper.getCarListByUsername", username);
	}

	@Override
	public String getDriverTelephoneByDriverId(long driverId) {
		// TODO Auto-generated method stub
		return this.sqlSessionTemplate.selectOne("com.huoyun.car.dao.CarDaoMapper.getDriverTelephoneByCarId",driverId);
	}
	
	@Override
	public List<Car> getCarListForCargoByAmount(long userId, String amount, long goodsId) {
		// TODO Auto-generated method stub
		Map<String,String> map=new HashMap<String,String>();
		map.put("userId", userId+"");
		map.put("amount", amount);
		map.put("goodsId", goodsId+"");
		return this.sqlSessionTemplate.selectList("com.huoyun.car.dao.CarDaoMapper.getCarListForCargoByAmount", map);
	}

	@Override
	public CarDriverOwnerModel getCarDriverOwnerModelByCarId(long id) {
		// TODO Auto-generated method stub
		return this.sqlSessionTemplate.selectOne("com.huoyun.car.dao.CarDaoMapper.getCarDriverOwnerModel", id);
	}
	
	@Override
	public Car getCarByCarNumber(String carNumber) {
		// TODO Auto-generated method stub
		return this.sqlSessionTemplate.selectOne("com.huoyun.car.dao.CarDaoMapper.getCarByCarNumber", carNumber);
	}

	@Override
	public long queryCarCount(QueryCarEvt queryCarEvt) {
		return sqlSessionTemplate.selectOne("com.huoyun.car.dao.CarDaoMapper.queryCarCount",queryCarEvt);
	}

	@Override
	public List<CarModel> getCarModelListByUserId(long userId) {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("com.huoyun.car.dao.CarDaoMapper.getCarModelListByUserId", userId);
	}

	@Override
	public List<CarUserCompanyModel> getLatestNCar(long topN) {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("com.huoyun.car.dao.CarDaoMapper.getLatestNCar",topN);
	}

}
